//
//  MiTuGiftApi.swift
//  MT
//
//  Created by M on 2019/12/18.
//  Copyright © 2019 张强. All rights reserved.
//

import Foundation
import Moya
import DeviceKit
import SwiftyRSA
import Security

import Result

enum MTRedPackApi {
    /// 发送红包
    case sendRedpack(_ requestParam: [String : Any])
    /// 领取红包
    case openRedpack(_ requestParam: [String : Any])
    /// 获取红包状态数据
    case getRedpack(_ requestParam: [String : Any])
    /// 查询红包收入 / 支出记录
    case queryRedpackList(_ requestParam: [String : Any])
    /// 聚会任务群主发红包
    case partySendRedpack(_ req: [String : Any])
}

// MARK: ------------------  ----------------------
extension MTRedPackApi: MTTargetType {
    
    var needCache: Bool {
        return false
    }
    
    /// 请求头
    var headers: [String : String]? {
        //return ["Access-Token": "I6w6XbQSWNQIsnB9zKFbtV7b"]
        return ["Access-Token": UserDefaults.MTUserCenter.token.storedString ?? ""]
    }

    /// 基路径
    public var baseURL: URL {
        return URL(string: AuthServerBaseUrl)!
    }
    
    /// 路径
    public var path: String {
        switch self {
        case .sendRedpack(_):
            return "/redpacketSend/sendRedpacket"
        case .openRedpack(_):
            return "/redpacketPull/pullRedpacket"
        case .getRedpack(_):
            return "/redpacketPull/getPullRedpacket"
        case .queryRedpackList(_):
            return "/redpacketPull/list"
        case .partySendRedpack(_):
            return "/party-task/sendRedpacketPartyTask"
        }
    }
    
    /// 请求方法
    public var method: Moya.Method {
        return .post
    }
    
    /// 参数
    var params: [String: Any]? {
        switch self {
        case let .sendRedpack(requestParam):
            return requestParam
        case let .openRedpack(requestParam):
            return requestParam
        case let .getRedpack(requestParam):
            return requestParam
        case let .queryRedpackList(requestParam):
            return requestParam
        case let .partySendRedpack(req):
            return req
        }
    }
    
}
